package duck_zhang.dao.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import common.CommonDao;

import pojo.Persion;
import pojo.Workunit;
import pojo.Wuuser;
import duck.dao.impl.CommonDaoImpl;
import duck_zhang.dao.WorkDao;

public class WorkDaoImpl implements WorkDao {

	private CommonDao cd=new CommonDaoImpl();
	public List<Workunit> myWorkunit(int id) throws Exception {
		List<Workunit> all=new ArrayList<Workunit>();
		List<Wuuser> works=null;
		try{
			String hql="from Wuuser where UserID="+id+"";
			works=cd.loadByQuery(hql,true);
			for(Wuuser w:works){
				all.add(w.getId().getWorkunit());
			}
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return all;
	}

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		WorkDao wd=new WorkDaoImpl();
//		System.out.println(wd.myWorkunit(1));
//		System.out.println(wd.viewMembers(2));
		System.out.println(wd.out(4, 2));

	}

	public boolean out(int userID, int wuid) throws Exception {
		String hql="from Wuuser where UserID="+userID+" and WUID="+wuid+"";
		Wuuser w=(Wuuser) cd.loadByQueryUneue(hql);
		if(w!=null)
			return cd.delete(w);
		else
			return false;
	}

	public List<Persion> viewMembers(int wuid) throws Exception {
		List<Persion> all=new ArrayList<Persion>();
		List<Wuuser> works=null;
		try{
			String hql="from Wuuser where WUID="+wuid+"";
			works=cd.loadByQuery(hql,true);
			for(Wuuser w:works){
				all.add(w.getId().getPersion());
			}
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return all;
	}

}
